<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="/public/jquery-1.8.3.min.js"></script>
    <style>
        iframe {
            width: 100%;
            height: 500px;
            border: 1px solid #000;
        }
    </style>
</head>
<body>
<h2>测试 window.location.href 跳转</h2>
<h1>iframe 跨域请求</h1>
<button id="refreshBtn"> 刷新iframe内容 </button>

<iframe id="targetIframe" src="http://localhost:8081/customer-service/get-product?productInfo=productId%3D7466&type=3&timestamp=1762946745545&hashCode=6ec60b38ff752bf9a8200724d016d7aa&companyId=80028951&shopId=jyshop"></iframe>

<script>
    (function(){
        var btn = document.getElementById('refreshBtn');
        var iframe = document.getElementById('targetIframe');
        function refreshIframe(){
            // 使用 iframe 的原始 src（或 data-src）并追加时间戳，避免缓存
            var src = iframe.getAttribute('data-src') || iframe.src;
            // 移除已有的时间戳参数 _ts（如果存在）
            src = src.replace(/([?&])_ts=\d+(&?)/, function(m, p1, p2){ return p2 ? p1 : ''; });
            var sep = src.indexOf('?') === -1 ? '?' : '&';
            iframe.src = src + sep + '_ts=' + Date.now();
        }

        btn.addEventListener('click', refreshIframe, false);
    })();
</script>
</body>
</html>
